package com.gxa.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.domain.entity.User;
import com.gxa.mapper.UserMapper;
import com.gxa.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * 万事顺意
 * Created with IntelliJ IDEA.
 * User: zwj
 * Date: 2024/07/1611:34
 * Description:
 */

/**
 * 登录
 */
@Transactional//开启事务 事务是指逻辑上的一组要操作，要么都成功，要么都是失败
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements UserService {
    @Override
    public User login(String phone, String password) {
        LambdaQueryWrapper<User> wrapper = Wrappers.lambdaQuery(User.class);
        wrapper.eq(User::getPhone, phone);
        wrapper.eq(User::getPassword,password);
        User one = this.getOne(wrapper);
        return one;
    }

    /**
     * 注册
     * @param user
     * @return
     */
    @Override
    public User register(User user){
        String phone=user.getPhone();
        LambdaQueryWrapper<User> wrapper=Wrappers.lambdaQuery(User.class);
        wrapper.eq(User::getPhone,phone);
        User one=this.getOne(wrapper);
        if (one!=null){
            return null;
        }
        boolean  save=this.save(user);
        return user;
    }
}




